package rapier.sso.server.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import rapier.sso.core.config.cache.RapierBaseCacheConstant;
import rapier.sso.core.entity.TDbSsoAppEntity;
import rapier.sso.core.entity.TDbSsoAuthEntity;
import rapier.sso.core.service.ITDbSsoAppAuthService;
import rapier.sso.core.service.ITDbSsoAppService;
import rapier.sso.core.service.ITDbSsoAuthService;

@Component
@CacheConfig(cacheNames = RapierBaseCacheConstant.RAPIER_SHORT_CACHE)
public class RapierAppsService {

	@Autowired
	private ITDbSsoAuthService ssoAuthService;

	@Autowired
	private ITDbSsoAppService ssoAppService;
	
	@Autowired
	private ITDbSsoAppAuthService appAuthService;

	/**
	 * 携带全新
	 * 
	 * @param clientId
	 * @return
	 */
	@Cacheable(value = "sso:app:auth:info:", key = "#appId")
	public TDbSsoAppEntity getAppAuthInfo(Long appId) {
		TDbSsoAppEntity entity = ssoAppService.getById(appId);
		if(entity != null) {
			List<TDbSsoAuthEntity> list = ssoAuthService.getAuthByAppId(appId);
			entity.getAuths().addAll(list);
		}
		return entity;
	}
}